package com.suxin.plugin.loader.load;

import com.suxin.plugin.loader.PluginResourceLoader;
import com.suxin.plugin.loader.ResourceWrapper;
import com.suxin.plugin.pf4j.BasePlugin;
import org.springframework.core.io.ClassPathResource;

import java.io.File;
import java.util.Collections;

/**
 * @author Tang
 * @classname PluginConfigFileLoader
 * @description [ 加载指定的文件 ]
 * @date 2022/7/21 22:37
 */
public class PluginConfigFileLoader implements PluginResourceLoader {

    private String configFilePath;
    private String fileName;

    public PluginConfigFileLoader(String configFilePath,String fileName) {
        this.configFilePath = configFilePath;
        this.fileName = fileName;
    }

    @Override
    public String key() {
        return null;
    }

    @Override
    public ResourceWrapper load(BasePlugin basePlugin) throws Exception{
        ClassPathResource classPathResource = new ClassPathResource("/" + configFilePath + File.separatorChar + fileName,
                basePlugin.getPluginWrapper().getClassLoader());
        return new ResourceWrapper(Collections.singletonList(classPathResource));
    }

    @Override
    public void unload(BasePlugin basePlugin, ResourceWrapper resourceWrapper) throws Exception {

    }
}
